package com.evil.common.family.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author liyang
 */
@AllArgsConstructor
public enum SexEnum {
    /**
     * 性别
     */
    MALE(0, "男"),
    FEMALE(1, "女");

    @Getter
    private final int id;
    @Getter
    private final String name;

    public static Optional<SexEnum> getById(Integer id) {
        if (null == id) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static Optional<SexEnum> getByName(String name) {
        if (StringUtils.isEmpty(name)) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.name.equals(name)).findFirst();
    }
}
